<template>
  <div>
    <x-table :cell-bordered="false" :content-bordered="false" style="background-color:#fff;">
      <thead>
      <tr style="background-color: #F7F7F7">
        <th>学生</th>
        <th>微信号</th>
      </tr>
      </thead>
      <tbody>
      <tr v-for="(value,index) in studentList">
        <td>{{value.studentName}}</td>
        <td>{{value.bindName}}</td>
      </tr>
      </tbody>
    </x-table>
  </div>
</template>
<script>
  import { XTable, Group, Cell } from 'vux'

  export default {
    components: {
      XTable,
      Group,
      Cell
    },
    created: function () {
      this.$http.get('/jeewx/studentController.do?searchStudent&studentName=全部')
        .then(function (res) {
          let json = JSON.parse(res.body.jsonStr)
          let studentList = json.obj
          this.$http.get('/wx/WxRobotController.do?getWxRobotContactInfo')
            .then(function (res) {
              this.friendList = res.body.friendList
              this.studentList = checkBind(studentList, this.friendList)
              localStorage.studentList = JSON.stringify(this.studentList)
            })
        })
    },
    methods: {
    },
    data () {
      return {
        studentList: [],
        friendList: [],
        value: ''
      }
    }
  }

  function checkBind (studentList, friendList) {
    let resultList = []
    studentList.forEach(function (value, index, array) {
      let studentName = value.chname
      let studentId = value.id
      let bindName = ''
      friendList.forEach(function (friend, index, array) {
        if (friend.remarkName.indexOf(studentName) !== -1) {
          bindName = bindName + friend.remarkName + ','
        }
      })
      if (bindName === '') {
        bindName = '未绑定'
      } else {
        bindName = bindName.substring(0, bindName.length - 1)
      }
      resultList.push({
        studentId: studentId,
        studentName: studentName,
        bindName: bindName
      })
    })
    return resultList
  }
</script>

<style scoped>


</style>
